<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //  函数作业
      const arr = [
        { uname: '孙六', age: 39 },
        { uname: '刘七', age: 21 },
        { uname: '刘七', age: 1 },
        { uname: '张三', age: 59 },
        { uname: '李四', age: 29 },
        { uname: '王二', age: 19 },
      ]
      // 前提克隆一份数据
      // 1，把age中个位数为9的替换成*  { uname: '孙六', age: 2* },

      let newarr = JSON.parse(JSON.stringify(arr))
      newarr.forEach((x) => {
        for (let k in x) {
          if (x[k] % 10 === 9) {
            x[k] = parseInt(x.age / 10) + '*'
          }
        }
      })
      console.log(newarr)

      // 2，把张三的这个对象干掉，添加个{uname:'老六',age: 12}
      for (let i = 0; i < newarr.length; i++) {
        if (newarr[i].uname === '张三') {
          newarr.splice(i, 1, { uname: '老六', age: 12 })
        }
      }
      console.log(newarr)

      // 3, 根据年龄排序 过滤到小于18岁的
      let res = arr.filter((x) => {
        if (x.age >= 18) {
          return x
        }
      })
      console.log(res)
    </script>
  </body>
</html>
